home *** CD-ROM | disk | FTP | other *** search
/ ADA Programming Guide / ADA Programming Guide.iso / ada_gnu / adainc / a-numran.ads < prev    next >
Text File  |  1996-01-30  |  4KB  |  88 lines

  1. ------------------------------------------------------------------------------
  2. --                                                                          --
  3. --                         GNAT RUNTIME COMPONENTS                          --
  4. --                                                                          --
  5. --                  A D A . N U M E R I C S . R A N D O M                   --
  6. --                                                                          --
  7. --                                 S p e c                                  --
  8. --                                                                          --
  9. --                            $Revision: 1.1 $                              --
  10. --                                                                          --
  11. --           Copyright (c) 1992,1993,1994 NYU, All Rights Reserved          --
  12. --                                                                          --
  13. -- GNAT is free software;  you can  redistribute it  and/or modify it under --
  14. -- terms of the  GNU General Public License as published  by the Free Soft- --
  15. -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
  16. -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
  17. -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
  18. -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
  19. -- for  more details.  You should have  received  a copy of the GNU General --
  20. -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
  21. -- to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. --
  22. --                                                                          --
  23. ------------------------------------------------------------------------------
  24.  
  25. --  This package provides the basic support used for the Float_Random and
  26. --  Discrete_Random children of Ada.Numerics. In this package, the generator
  27. --  state is exposed for access but this is a private package so no problem.
  28.  
  29. private package Ada.Numerics.Random is
  30.  
  31.    --  All the arithmetic is done using a base type that is at least
  32.    --  32 bits long (one's complement or two's complement, does not
  33.    --  matter). It also must be at least as large as integer.
  34.  
  35.    type Int_Range is range
  36.       Long_Integer'Min (Long_Integer (Integer'First), (-2 ** 31) + 1) ..
  37.       Long_Integer'Max (Long_Integer (Integer'Last),  (+2 ** 31) - 1);
  38.  
  39.    type Int is new Int_Range'Base;
  40.    subtype Nat is Int range 0 .. Int'Last;
  41.    --  The types that we will actually use
  42.  
  43.    --  The following declarations define the type State, which is used as the
  44.    --  underlying type for both Generator and State in the user level packages
  45.  
  46.    Larger_Lag  : constant := 25;
  47.    Smaller_Lag : constant := 11;
  48.    --  Lag values used for modular accessing of the state vector
  49.  
  50.    type Lag_Range is mod Larger_Lag;
  51.    --  Range of larger lag is length of state vector
  52.  
  53.    type State_Vector is array (Lag_Range) of Float;
  54.  
  55.    type State is record
  56.       Lagged_Outputs : State_Vector;
  57.       Borrow         : Float;
  58.       R, S           : Lag_Range;
  59.    end record;
  60.  
  61.    subtype Uniformly_Distributed is Float range 0.0 .. 1.0;
  62.    --  Range of random numbers
  63.  
  64.    procedure Random (S : in out State; U : out Uniformly_Distributed);
  65.    --  Obtain next random number, updating State
  66.  
  67.    function Make_State (Starter : Int := 3E+7) return State;
  68.    --  Build a state from the given integer value. The default value for
  69.    --  Int is used to build the default starting generator configurations.
  70.  
  71.    procedure Reset (S : out State; Initiator : in Integer);
  72.    --  Set state from given integer value
  73.  
  74.    procedure Reset (S : out State);
  75.    --  Set state from current time
  76.  
  77.    Max_Image_Width : constant := (24 + 1) * 25 + 24;
  78.    --  The 24 + 1 is for one floating point value plus a comma, and there
  79.    --  are up to Larger_Lag number of these, followed by one additional value
  80.  
  81.    function Image (S : State)  return String;
  82.    --  Convert state to canonical string format (see body for format)
  83.  
  84.    function Value (S : String) return State;
  85.    --  Convert string returned by previous image call back to State
  86.  
  87. end Ada.Numerics.Random;
  88.